package org.visionlibrary.image.geomtric.model;

public class LinearPolarFunction implements LinearFunction1d {
	private double theta;
	private double r;
	
	public LinearPolarFunction() {
		this(Math.toRadians(45.0d), Math.sqrt(2));
	}
	
	public LinearPolarFunction(double theta, double r) {
		this.theta = theta;
		this.r = r;
	}
	
	@Override
	public double evaluateY(double x) {
		return (r - (x*Math.cos(theta)))/Math.sin(theta);
	}
	
	@Override
	public double evaluateX(double y) {
		return (r -  y*Math.sin(theta) )/(Math.cos(theta));
	}

	@Override
	public double getDirectionFactor() {
		return Math.cos(theta)/Math.sin(theta);
	}
	
	@Override
	public String toString() {
		return new String("y = " + r + "/sin(" + theta + ") + x*cos(" + theta + ")/sin(" + theta + ")");
	}

}
